package com.dragon.shop.utils.resp;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.HashMap;

/**
 * @author: Dragon
 * @since: 2023/11/11 10:55
 */
@Data
@AllArgsConstructor
public class ResponseEntity {

    private Integer code;

    private String Msg;

    private Object data;

    long time;

    public ResponseEntity(Object data) {
        this.time = System.currentTimeMillis();
        this.code = 0;
        this.data = data;
    }

    public ResponseEntity() {
        this.time = System.currentTimeMillis();
        this.code = 0;
        this.Msg = "success";
    }

    public ResponseEntity(int code, String msg, Object data) {
        this.time = System.currentTimeMillis();
        this.code = code;
        this.Msg = msg;
        this.data =data;
    }

    public ResponseEntity(int code, String msg) {
        this.time = System.currentTimeMillis();
        this.code = code;
        this.Msg = msg;
    }

    @Override
    public String toString() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", code);
        map.put("time", time);
        map.put("msg", Msg);
        map.put("data", data);

        return JSON.toJSONString(map);
    }
}
